<template>
  <div class="c-w100 c-page-bg c-content-auto" v-if="redeemCodeInfo">
    <div class="c-p c-pz1 c-ww640">
      <img class="c-pa c-pz-1 c-ww640" :class="dataStatus == 'NO_DATA' ? 'c-h100vh' : 'c-hh540'" :src="require(dataStatus == 'NO_DATA' ? `@/assets/i/wap/coupon/bg3.png` : `@/assets/i/wap/coupon/bg.png`)" alt="">
      <div class="c-p c-pz1 c-ww640 c-hh640 c-pt30">
        <img class="c-pa c-pz-1 c-ww640 c-hh640" :src="require('@/assets/i/wap/coupon/bg2.png')" alt="">
        <div class="c-pt40 c-flex-row c-aligni-center c-justify-sb c-ph80">
          <img class="c-ww80 c-hh80 c-brp50 c-flex-shrink0" :src="$addXossFilter(redeemCodeInfo.headimgurl || companyLogo)" alt="">
          <span class="c-ml20 c-flex-grow1 c-w0 c-fs28 c-fc-sblack c-text-ellipsis1">{{redeemCodeInfo.nickName || companyName}}</span>
        </div>
        <div class="c-flex-column c-aligni-center">
          <coupon-item-com  :couponInfo="redeemCodeInfo" :showFooter="false" :source="7" :size="'small'" class="c-mt60 c-ww480">
          </coupon-item-com>
          <!-- <div class="c-mt60 c-p c-hh160 c-ww480">
            <div class="c-pa c-pz1 c-fs72 iconfont c-p-r10 c-p-t10 c-fc-sgray" v-if="hasGet && (resultStatus == 6 || resultStatus == 8)">&#xe939;</div>
            <img class="c-pa c-pz-1 c-hh160 c-ww480" :src="require('@/assets/i/wap/coupon/coupon-bg.png')" alt="">
            <div class="c-flex-row c-aligni-center c-justify-sb">
              <div class="c-ww130 c-hh160 c-flex-shrink0 c-flex-row c-flex-center c-fc-white c-fs20">
                <div class="c-fs32 c-fc-white" v-if="redeemCodeInfo.type == 1 || redeemCodeInfo.type == 4">
                  {{redeemCodeInfo.type == 1 ? '兑换券' : '抵价券'}}
                </div>
                <div v-else class="c-flex-column c-aligni-center">
                  <div v-if="redeemCodeInfo.type == 5" class="c-fw-b c-pb10 c-fs40">{{Number(redeemCodeInfo.price)}}<span class="c-fs20">折</span></div>
                  <div v-else class="c-fw-b c-pb10">{{'￥' | iosPriceFilter}}<span :class="Number(redeemCodeInfo.price).toFixed(0) > 9999 ? 'c-fs32' : 'c-fs40'">{{Number(redeemCodeInfo.price).toFixed(0)}}</span></div>
                  <div>{{Number(redeemCodeInfo.amount) > 0 ? '满'+Number(redeemCodeInfo.amount)+'可用' : '无门槛'}}</div>
                </div>
              </div>
              <div class="c-flex-grow1 c-hh160 c-ph24 c-flex-column c-justify-sb c-pv16">
                <div class="c-ww320 c-fc-xblack c-fs28 c-fw600 c-text-ellipsis1">
                  <span class="c-text-ellipsis1 c-lh32">{{redeemCodeInfo.name}}</span>
                </div>
                <div class="c-fs20 c-fc-gray c-ww320 c-text-ellipsis1" v-if="redeemCodeInfo.type == 2 || redeemCodeInfo.type == 3 || redeemCodeInfo.type == 5">{{redeemCodeInfo.redeemType == 26 ? '适用于知识商品' : redeemCodeInfo.redeemType == 25 ? '适用于商城商品' : redeemCodeInfo.redeemType == 114 ? '适用于预约师资功能' : redeemCodeInfo.redeemType == 27 ? ("适用于" + (redeemCodeInfo.prodTypes ? redeemCodeInfo.prodTypes.join('、') : '')) : '指定商品可用'}}</div>
                <div class="c-fs20 c-fc-gray c-wb-ba">
                  <div v-if="redeemCodeInfo.validStatus != 1 && redeemCodeInfo.validStatus != 2 && redeemCodeInfo.startAt && redeemCodeInfo.endAt">
                    {{redeemCodeInfo.startAt.split(" ")[0]}}-{{redeemCodeInfo.endAt.split(" ")[0]}}
                  </div>
                  <div v-else>
                    {{redeemCodeInfo.validStatus == 1 ? ('领券当日起' + redeemCodeInfo.validPeriod + '天内可用') : ('领券次日起' + redeemCodeInfo.validPeriod + '天内可用')}}
                  </div>
                </div>
              </div>
            </div>
          </div> -->
        </div>
        <div class="c-flex-column c-flex-center" :class="redeemCodeInfo.type == 1 ? 'c-mt140' : 'c-mt110'">
          <div class="c-flex-row">
            <div v-if="isReceive == 1" @click="submitApply" class="c-ww240 c-hh76 c-fs28 c-fw500 c-fc-xlblown c-textAlign-c c-flex-row c-flex-center btn c-br40 c-mr40">继续领取</div>
            <div v-if="((type == 2 && redeemCodeInfo.isLock == 1) || (type == 1 && redeemCodeInfo.isSales == 3)) && !(isGift && !!eRcdId)" @click="goBuy" :class="isReceive == 1 ? 'c-ww240' : 'c-ww460'" class="c-hh76 c-fs28 c-fw500 c-fc-xlblown c-textAlign-c c-flex-row c-flex-center btn c-br40">立即购买</div>
            <!-- isGift == 1 领取优惠券的链接   giftStatus 优惠券状态 1转赠中 0非转赠 -->
            <div v-else-if="!hasGet" @click="submitApply" :class="isReceive == 1 ? 'c-ww240' : 'c-ww460'" class="c-hh76 c-fs28 c-fw500 c-fc-xlblown c-textAlign-c c-flex-row c-flex-center btn c-br40">{{redeemCodeInfo.type == 1 && redeemCodeInfo.prodInfo && !redeemCodeInfo.enableGift ? '立即兑换' : '立即领取'}}</div>
            <div v-else-if="hasGet && (resultStatus == 8 || (hasOldCode && resultStatus != 6))" @click="goToExchange" :class="isReceive == 1 ? 'c-ww240' : 'c-ww460'" class="c-hh76 c-fs28 c-fw500 c-textAlign-c c-m-0auto has-get-bg c-br40 c-flex-row c-flex-center">{{redeemCodeInfo.type == 1 ? '立即兑换' : '立即使用'}}</div>
            <div v-else-if="hasGet && (resultStatus == 6 || resultStatus == 15) && redeemCodeInfo.prodInfo" @click="goProduct(redeemCodeInfo.prodInfo.prodType, redeemCodeInfo.prodInfo.id, redeemCodeInfo.prodInfo.courseType)" :class="isReceive == 1 ? 'c-ww240' : 'c-ww460'" class="c-hh76 c-fs28 c-fw500 c-textAlign-c c-m-0auto has-get-bg c-br40 c-flex-row c-flex-center">立即查看</div>
            <div v-else-if="hasGet" @click="goHome" :class="isReceive == 1 ? 'c-ww240' : 'c-ww460'" class="c-hh76 c-fs28 c-fw500 c-textAlign-c c-flex-row c-flex-center has-get-bg c-br40">进入首页</div>
          </div>
          <!--转赠好友--><!-- 可分享 && 非转赠 才显示分享好友-->
          <div class="c-fs28 c-fw400 c-fc-f2 c-textAlign-c c-mt24"><span @click="showShareCom()" v-if="hasGet && isShowEx && redeemCodeInfo.enableGift">转赠好友<span v-if="redeemCodeInfo.enableShare == 1 && isGift == 0" class="c-mh28">|</span></span><span v-if="redeemCodeInfo.enableShare == 1 && isGift == 0" @click="drawShareImg">分享给好友</span></div>
        </div>
      </div>
    </div>
    <div class="c-flex-row c-flex-center c-mt30 c-mb30">
      <img class="c-hh44 c-ww480" :src="redeemCodeInfo.type == 1 ? require('@/assets/i/wap/coupon/prod2.png') : require('@/assets/i/wap/coupon/prod.png')" alt="">
    </div>
    <div v-if="exchangeArr && exchangeArr.length > 0" class="c-flex-row c-justify-sb c-ph24">
      <water-fall v-model="exchangeArr" ref="waterfall">
        <template v-slot:list="{list}">
          <div class="c-p c-br8 c-bg-white c-ph8 c-pv8 c-m5" v-if="!!lItem.prodInfo" @click="goProduct(lItem.prodInfo.prodType, lItem.prodInfo.id, lItem.prodInfo.courseType)" v-for="(lItem, lIndex) in list" :key="lIndex">
            <div class="c-ww282 c-maxh188 c-br10 c-mb20 c-p">
              <div v-if="lItem.prodInfo.prodType != 86" class="c-ww282 c-maxh188 c-br10 c-text-hidden c-flex-shrink0">
                <img v-if="lItem.prodInfo.prodType == 1 || lItem.prodInfo.prodType == 23" class="c-w100 c-br4" :src="$addXossFilter((lItem.prodInfo.avatar && lItem.prodInfo.avatar.coverType == 2) ? lItem.prodInfo.avatar.coverUrl : (lItem.prodInfo.avatar && lItem.prodInfo.avatar.coverType == 1) ? require('../../../assets/i/wap/vip/vip-bg-mb' + lItem.prodInfo.avatar.coverUrl + '.png') :  (lItem.prodInfo.prodType == 1 ? require('@/assets/i/wap/course/vip.png') : require('@/assets/i/wap/course/svip.png')))" alt="">
                <img v-else class="c-w100 c-br4" :src="$addXossFilter(lItem.prodInfo.avatar ? lItem.prodInfo.avatar : lItem.prodInfo.prodType == 11 ? require('../../../assets/examination_defult.png') : require('../../../assets/defult270.png'))" alt="">
              </div>
              <div v-else class="c-ww282 c-hh188 c-br10 c-flex-row c-justify-center c-flex-shrink0">
                <img class="c-ww282 c-hh188 c-br10" :src="$addXossFilter(lItem.prodInfo.avatar, require('../../../assets/defult270.png'))" alt="">
              </div>
              <div class="c-pa c-p-b0 c-p-r0 c-fs16 c-fc-white c-ph8 c-translucent-balck60 c-translucent-balck6 c-tag-br12 c-pv2">
                {{lItem.prodInfo.prodType == 51 ? '公开课' : lItem.prodInfo.prodType == 5 ? courseTypeObj[lItem.prodInfo.courseType] : prodMapType[lItem.prodInfo.prodType]}}
              </div>
            </div>
            <div class="c-ww282 c-fs24 c-pb20">
              <div class="c-text-ellipsis1 c-mb10">{{lItem.prodInfo.name}}</div>
              <div class="c-flex-row">
                <div class="c-fs20 c-fc-gray" v-if="lItem.prodInfo.prodType == 118">此课程仅支持线下报名，请联系商家使用优惠券报名</div>
                <div v-else class="c-fc-xmlred c-fs24 c-fw400">
                  <span v-if="lItem.prodInfo.payType == 2 || lItem.prodInfo.payType == 4">{{'￥' | iosPriceFilter}}</span>{{lItem.prodInfo.payType | priceValueFilter(lItem.prodInfo.prodPrice, lItem.prodInfo.prodType)}}
                </div>
              </div>
            </div>
          </div>
        </template>
      </water-fall>
    </div>
    <loading-status-tem v-if="dataStatus != 'NO_DATA'" :dataStatus="dataStatus" noDataText="当前暂无推荐商品"></loading-status-tem>
    <div v-show="showMask" class="c-pz10">
      <div class="c-translucent-balck50 c-pf c-p-t0 c-p-b0 c-p-l0 c-p-r0 c-pz10" @click="showMask = false"></div>
      <div class="c-pf c-p-t0 c-p-b0 c-p-l0 c-p-r0 c-ww600 c-table margin-auto c-pz10">
        <img src="" class="c-w100" id="shareSpreadImg" />
        <div class="c-fs22 c-fc-white c-textAlign-c">长按上方图片保存并分享</div>
        <div class="c-fs36 c-fc-white c-pa c-p-t0 c-p-r20 iconfont" @click="showMask = false">&#xe84e;</div>
      </div>
    </div>
    <div class="w600px canvasBox" id="shareCanvas">
      <img class="c-w100" src="https://ckjr-static-assets.oss-cn-shanghai.aliyuncs.com/assets/img/public/bargin-share.png" alt="">
      <div class="c-pa c-p-t0 c-p-l0 c-w100">
        <div class="w440px c-m-0auto c-flex-row c-aligni-center mt130 pl40px">
          <img class="c-ww72px c-hh72px c-brp50" :src="$addXossFilter(userHeadImg)" alt="">
          <div class="c-flex-column c-justify-sb c-ml16px c-hh72px">
            <div class="c-fs24px c-fc-blue c-fw400">{{userName}}</div>
            <div class="c-fs20px c-fc-sblack c-fw400">分享一张优惠券给你</div>
          </div>
        </div>
        <div class="c-flex-row c-justify-sb c-aligni-center c-p c-text-hidden c-ww380px c-m-0auto c-mt56px c-bg-white c-bd1-xlred c-br8px">
          <div class="c-fc-xmlred c-fs20px c-hh140px c-ww140px c-flex-row c-flex-center c-textAlign-c">
            <div class="exchange-left-bg" v-if="redeemCodeInfo.type == 1">
              <!-- {{redeemCodeInfo.type == 1 ? '兑换券' : '抵价券'}} -->
            </div>
            <div v-else-if="redeemCodeInfo.type == 4">
              <div class="c-fw-b c-pb10px c-fs32px">抵价券</div>
              <div>无门槛</div>
            </div>
            <div v-else>
              <div v-if="redeemCodeInfo.type == 5" class="c-fw-b c-pb10px c-fs40px">{{Number(redeemCodeInfo.price)}}<span class="c-fs20px">折</span></div>
              <div v-else class="c-fw-b c-pb10px">{{'￥' | iosPriceFilter}}<span :class="redeemCodeInfo.price.length > 6 ? 'c-fs24px' : redeemCodeInfo.price.length > 4 ? 'c-fs32px' : 'c-fs40px'">{{redeemCodeInfo.price}}</span></div>
              <div>{{Number(redeemCodeInfo.amount) > 0 ? '满'+Number(redeemCodeInfo.amount)+'可用' : '无门槛'}}</div>
            </div>
          </div>
          <div class="c-p c-flex-row c-justify-sb c-aligni-center c-fc-gray c-hh140px c-w0 c-flex-grow1 c-ph12px c-pv17px">
            <div :class="redeemCodeInfo.type == 2 || redeemCodeInfo.type == 3 || redeemCodeInfo.type == 5 ? 'c-justify-sb' : 'c-justify-sa'" class="c-w0 c-flex-grow1 c-flex-column c-h c-text-hidden">
              <div class="c-fc-xblack c-fs22px c-text-ellipsis1 c-w100">{{formatLength(redeemCodeInfo.name, 11)}}</div>
              <div class="c-fs20px" v-if="redeemCodeInfo.validStatus != 1 && redeemCodeInfo.validStatus != 2 && redeemCodeInfo.startAt && redeemCodeInfo.endAt">
                {{redeemCodeInfo.startAt.substr(0,10).replace(/-/g, ".")}}-{{redeemCodeInfo.endAt.substr(0,10).replace(/-/g, ".")}}
              </div>
              <div class="c-fs20px" v-else>
                {{redeemCodeInfo.validStatus == 1 ? ('领券当日起' + redeemCodeInfo.validPeriod + '天内可用') : ('领券次日起' + redeemCodeInfo.validPeriod + '天内可用')}}
              </div>
              <div v-if="redeemCodeInfo.type == 2 || redeemCodeInfo.type == 3 || redeemCodeInfo.type == 5" class="c-fs20px c-text-ellipsis1">{{redeemCodeInfo.redeemType == 26 ? '全店商品可用' : redeemCodeInfo.redeemType == 25 ? '适用于商城商品' : redeemCodeInfo.redeemType == 114 ? '适用于预约师资功能' : redeemCodeInfo.redeemType == 27 ? (("适用于" + (redeemCodeInfo.prodTypes ? redeemCodeInfo.prodTypes.join('、') : '')).length > 11 ? (("适用于" + (redeemCodeInfo.prodTypes ? redeemCodeInfo.prodTypes.join('、') : '')).substring(0, 10) + '...') : ("适用于" + (redeemCodeInfo.prodTypes ? redeemCodeInfo.prodTypes.join('、') : ''))) : '指定商品可用'}}</div>
            </div>
          </div>
        </div>
        <div class="c-mt100px">
          <img v-if="redeemCodeInfo.qrCodeImg" class="c-ww130px c-hh130px c-br4 c-center" :src="$addXossFilter(shareQrCode || redeemCodeInfo.qrCodeImg)" alt="">
          <div v-else class="c-ww130px c-hh130px c-br4 c-center c-bg-white"></div>
          <div class="c-fs22px c-fc-white c-textAlign-c c-mt24px">长按扫码，领取优惠券</div>
        </div>
      </div>
    </div>
    <share-com :isShow="isOpenSharePopup" @closeSharePopup="closeSharePopup" :item="redeemCodeInfo"></share-com>
  </div>
</template>
<script>
import { utilJs } from "@/utils/common.js";
import { goDetails } from "@/utils/goDetails.js";
import { getBindPhoneSetting } from "@/utils/checkUnBindPhone.js";
import loadingStatusTem from "@/components/templates/common/loadingStatusTem.vue";
import waterFall from "@/components/templates/common/waterfall.vue"
import shareCom from "@/components/templates/myValueVoucher/shareCom.vue";
import couponItemCom from "@/components/templates/couponItemCom.vue";
let html2canvas = null;
let isLoading = false;
let pageIndex = 1; //页码
export default {
  name: 'GetExchangeCode',
  components: {
    loadingStatusTem,
    waterFall,
    shareCom,
    couponItemCom
  },
  data() {
    return {
      theme: localStorage.getItem("colorName") ? localStorage.getItem("colorName") : 'mb5_default',
      rUserId: "",
      exchangeCode: "",
      codeStatus: -999,
      redeemCodeInfo: "",
      redeemCodeId: -1,
      resultStatus: -999,
      showMask: false,
      type: '',
      showUse: false,
      buttonText: "立即使用",
      startAt: '',
      endAt: '',
      isGoUse: false,
      hasGet: false,
      hasOldCode: false, //领取失败，但是之前有领取过
      userHeadImg: localStorage.getItem("userHeadImg") ? localStorage.getItem("userHeadImg") : '',
      userName: localStorage.getItem("userName") ? localStorage.getItem("userName") : '',
      companyName: localStorage.getItem("companyName") ? localStorage.getItem("companyName") : '',
      companyLogo: localStorage.getItem("shareLogo") ? localStorage.getItem("shareLogo") : '',
      couponStatus: {
        1: '该优惠券未开始',
        2: '进行中',
        3: '该优惠券已停止',
        4: '该优惠券已过期',
        5: '该优惠券已作废',
        6: '您已有权限，不用再领取',
        7: '您不符合领取要求',
        8: '领取成功',
        9: '您领取次数已达到上限',
        10: '该优惠券已被领取',
        11: '您来晚了，已被领取完了',
        12: '您已经领取过了',
        16: '兑换的商品不存在',
        17: '小班课学员已满,兑换失败',
        18: '小班课已下架,兑换失败',
        19: '小班课报名已结束,兑换失败'
      },
      oldStartAt: "",
      oldEndAt: "",
      hasNoRecommendation: false,
      exchangeArr: [],
      dataStatus: 'HAS_MORE_DATA',
      eRcdId: '', // 需要把eRcdId传给领取接口，领取指定赠送的那张优惠券
      isGift: 0, // 是否是转赠优惠券 1是 0否
      shareQrCode: '', // 转赠二维码
      prodMapType: global.prodMapType,
      courseTypeObj: {
        0: '视频',
        1: '音频',
        2: '图文',
      },
      bindPhoneSetting: null,
      enableRelatedForm: 0,
      isOpenSharePopup: false,
      eExchangeCode: 0, // 领取后的劵码
      isShowEx: false, // 是否显示转赠好友, 兑换券，并且允许转赠，已经领取了券，并且没兑换过
      isReceive: 0 //1:可以继续领取 0：不能继续领取
    }
  },
  created() {
    utilJs.appShare(this);
  },
  mounted() { },
  computed: {},
  watch: {},
  methods: {
    formatLength(val, len) {
      return val.length <= len ? val : val.substring(0, len - 2) + '...';
    },
    toExchangeActivity(data = {}, rcdId, ticketId) {
      let goPathQuery = {
        activityId: data.activityId,
        ticketId: ticketId,
        isFree: data.isFree,
        isAudit: data.isAudit,
        recType: '',
        recRelateId: '',
        ticketName: data.name,
        minNum: 1,
        maxNum: 1,
        selectPrice: 0,
        rcdId: rcdId
      };
      //如果有关联表单，先跳表单页填写完再到填票页
      let path = '/activity/activityEnroll';
      let query = goPathQuery;
      // collectPage：1购买前 && 有关联表单 && 未填写过关联表单 && 有打开表单模块
      if (data.collectPage == 1 && data.isRelForm == true && data.hasFormLog == false && localStorage.getItem("showForm") == 1) {
        path = '/homePage/form';
        query = {
          cId: -1,
          extId: data.activityId,
          ckFrom: global.ckFrom.activity,
          relType: 7,
          type: 1,
          rcdId: rcdId,
          goBillQuery: encodeURIComponent(JSON.stringify(goPathQuery))
        }
      }
      this.$routerGo(this, "push", {
        path: path,
        query: query
      })
    },
    // 获取活动票券信息
    getActivityInfo(activityId, rcdId, ticketId) {
      utilJs.postMethod(`${global.apiurl}activities/mgticket`, { activityId: activityId, collageId: -1, groupId: -1 }, (res) => {
        const list = res.data || []
        const formRet = res.formRet || {}
        let ticketItem = list.filter(i => i.prodId == ticketId)[0] || {}
        ticketItem = {...formRet, ...ticketItem}
        let stime = ticketItem ? utilJs.getTimeByDate(ticketItem.startAt) : 0;
        let etime = ticketItem ? utilJs.getTimeByDate(ticketItem.endAt) : 0;
        let nowTime = (new Date()).getTime();
        if (stime && stime > nowTime) {
          this.$showCjToast({ text: "活动报名未开始，不支持兑换", type: "warn", time: 3000 });
          return
        }
        if (etime && etime < nowTime) {
          this.$showCjToast({ text: "活动报名已结束，不支持兑换", type: "warn", time: 3000 });
          return
        }
        if (!ticketItem.prodId) {
          this.$showCjToast({ text: "兑换的活动票已删除，不支持继续兑换", type: "warn", time: 3000 });
          return
        }
        this.toExchangeActivity(ticketItem, rcdId, ticketId)
      });
    },
    showShareCom() {
      this.redeemCodeInfo.redeemCodeId = this.redeemCodeInfo.redeemCodeId == -1 ? this.redeemCodeInfo.redeemCodeId2 : this.redeemCodeInfo.redeemCodeId;
      this.isOpenSharePopup = true;
    },
    closeSharePopup() {
      this.isOpenSharePopup = false;
    },
    goBuy() {
      if (this.redeemCodeInfo.id) {
        let data = {id: this.redeemCodeInfo.id};
        if (this.$route.query.agentId) {
          data.agentId = this.$route.query.agentId;
        }
        this.$routerGo(this, "push", { path: '/member/myExchange/valuableCoupon', query: data });
      } else {
        let $this = this;
        this.$showCjToast({
          text: "暂不能购买",
          type: "warn",
        }).then(() => {
          $this.$routerGo($this, "push", { path: "/" });
        });
        return;
      }
    },
    isGoForm() {
      if (this.redeemCodeInfo.isRelForm == true && this.redeemCodeInfo.hasFormLog == false && localStorage.getItem("showForm") == 1) {
        this.goForm()
        return true;
      } else {
        return false;
      }
    },
    goForm() {
      let pathQuery = null;
      pathQuery = {
        relId: this.redeemCodeInfo.redeemCodeId,
        cId: -1,
        extId: this.redeemCodeInfo.redeemCodeId,
        ckFrom: global.ckFrom.coupon,
        isFromInvite: 0,
        pId: null,
        relType: 23,
        type: 1,
        recRelateId: this.$route.query.recRelateId,
        recType: this.$route.query.recType,
        isGoBack: 1,
        bargainId: ''
      };
      if (this.goodsRoomId) {
        pathQuery.goodsRoomId = this.goodsRoomId;
      }
      this.$routerGo(this, "push", { path: '/homePage/form', query: pathQuery });
    },
    // 获取可用该券的产品
    getCouponProds: function () {
      // 兑换券和抵用券不需要商品列表
      if (this.dataStatus == 'LOADING' || this.redeemCodeInfo.type == 4) {
        this.dataStatus = this.redeemCodeInfo.type == 4 ? 'NO_DATA' : this.dataStatus
        return;
      }
      this.dataStatus = 'LOADING';
      let postUrl = `${global.apiurl}coupon/suitablePro/${this.redeemCodeInfo.redeemCodeId || this.exchangeCode}?page=${pageIndex}&limit=15`;
      utilJs.getMethod(postUrl, res => {
        this.exchangeArr = this.exchangeArr.concat(res.data);
        if (res.data && (res.data.length < 15)) {
          this.dataStatus = pageIndex == 1 && res.data.length == 0 ? 'NO_DATA' : 'NO_MORE_DATA';
        } else {
          this.dataStatus = 'HAS_MORE_DATA';
          pageIndex++;
        }
      }, failRes => {
        this.dataStatus = 'DATA_ERROR';
      })
    },
    //下滑获取更多
    windowScrollFunction() {
      utilJs.handleLoading(() => {
        if (this.dataStatus == 'HAS_MORE_DATA' && this.exchangeArr.length > 0) {
          this.getCouponProds();
        }
      });
    },
    drawShareImg() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.shareBind) {
        if (utilJs.goBindMobile()) return;
      }
      import(/* webpackChunkName: "html2canvas" */"@/utils/html2canvas.js").then(res => {
        html2canvas = res.default;
        this.startCanvas();
      })
    },
    startCanvas() {
      let domTest = document.getElementById("shareCanvas");
      if (!domTest) {
        return;
      }
      this.$loading.show({
        text: "分享图片生成中"
      });
      html2canvas(domTest, { useCORS: true, backgroundColor: 'rgba(0, 0, 0, 0)' }).then(canvas => {
        let ctx = canvas.getContext("2d");
        this.canvasToImage(ctx);
      });
    },
    canvasToImage(ctx) {
      try {
        let dataURL = ctx.canvas.toDataURL("image/png?x-oss-process=style/common");
        document.getElementById("shareSpreadImg") && document.getElementById("shareSpreadImg").setAttribute("src", dataURL);
        this.showMask = true;
        this.$loading.hide();
      } catch (err) {
        this.$loading.hide();
        console.log(err.message);
        console.log(err.stack);
      }
    },
    goToUse: function () {
      this.isGoUse = true;
    },
    goProduct: function (rType, rId, courseType, codeType) {
      if (codeType == 1) {
        localStorage.setItem("couponType", 1);
        this.$routerGo(this, "push", {
          path: "/member/myValueVoucher/myValueVoucher"
        });
      } else {
        if (rType == 26) {
          this.$routerGo(this, "push", {path: "/"});
        } else if ((rType == 1 || rType == 23) && this.cType == 1) {
          this.$routerGo(this, "push", {
            path: "/member/memberIndex"
          });
        } else {
          goDetails(this, rType, rId, '', courseType);
        }
      }
    },
    //点击领取按钮
    submitApply: function () {
      if (this.isGoForm()) return;
      if (this.isGift && !!this.eRcdId) { // 有传eRcdId说明是转赠的优惠券
        this.getReceiveCoupon();
      } else if (this.type == 1) {
        this.getCouponPack();
      } else {
        this.getSingleCoupon();
      }
    },
    getSingleCoupon: function () {
      if (localStorage.getItem("enableBindPhoneInRedeemCode") == 1 && !localStorage.getItem("uMobile")) {
        utilJs.goBindMobile()
        return
      }
      if (isLoading) {
        return;
      }
      isLoading = true;
      this.$loading.show();
      let $this = this;
      //sourse = 7 优惠券从分享页面领取
      let postData = {
        source: 7
      }
      if (this.$route.query.sourceForm) {
        postData.sourceForm = this.$route.query.sourceForm
      }
      if (this.$route.query.agentId) { // 因为优惠券支持多个服务商，所以要传具体从哪个服务商分享出来的
        postData.agentId = this.$route.query.agentId;
      }
      utilJs.postMethod(`${global.apiurl}redeemCodes/collectRcdId/${this.exchangeCode}`, postData, res => {
        isLoading = false;
        this.resultStatus = res.status;
        if (this.redeemCodeInfo.validStatus == 1 || this.redeemCodeInfo.validStatus == 2) {
          this.redeemCodeInfo.startAt = res.startAt;
          this.redeemCodeInfo.endAt = res.endAt;
        }
        this.hasGet = true;
        this.$loading.hide();
        if (this.resultStatus == 8) {
          this.redeemCodeInfo.eRcdId = res.eRcdId;
          this.eExchangeCode = res.eRcdId;
          if (this.redeemCodeInfo.enableGift) {
            this.isShowEx = true;
          }
          if (this.redeemCodeInfo.type == 1 && this.redeemCodeInfo.prodInfo && this.redeemCodeInfo.prodInfo.permission) {
            this.resultStatus = 6;
            // this.isShowEx = false;
          }
          this.$showCjToast({
            text: "领取成功",
            type: "success",
          }).then(() => {
            // -1 未使用, 0 被占用，1 已使用, 2 线下核销
            const useStatus = [0, 1, 2].includes($this.redeemCodeInfo.useStatus)
            // 已领取的优惠券未使用 && 有eRcdId && 不能转赠（能转赠还需要再点一次立即兑换，不会自动跳）&& 活动类型
            if (!useStatus && $this.redeemCodeInfo.type == 1 && $this.redeemCodeInfo.eRcdId && !$this.redeemCodeInfo.enableGift && $this.redeemCodeInfo.prodInfo && $this.redeemCodeInfo.prodInfo.prodType == global.ckFrom.activity) {
              // 活动票券兑换流程
              $this.getActivityInfo($this.redeemCodeInfo.prodInfo.id, $this.redeemCodeInfo.eRcdId, $this.redeemCodeInfo.prodInfo.subId)
            }
          });
        } else if (this.resultStatus == 15) {
          //15:兑换券只能兑换一种商品，则领取后直接兑换成功
          this.redeemCodeInfo.eRcdId = res.eRcdId;
          this.eExchangeCode = res.eRcdId;
          if (this.redeemCodeInfo.prodInfo && this.redeemCodeInfo.prodInfo.prodType == global.ckFrom.shopping) {
            this.getShopInfo(this.redeemCodeInfo.prodInfo.id, this.redeemCodeInfo.eRcdId);
          } else {
            this.$showCjToast({
              text: "兑换成功",
              type: "success",
              time: 1000
            });
          }
        } else if (this.resultStatus == 17 || this.resultStatus == 18 || this.resultStatus == 19) {
          //15:兑换券只能兑换一种商品，则领取后直接兑换成功
          this.redeemCodeInfo.eRcdId = res.eRcdId;
          this.eExchangeCode = res.eRcdId;
          if (this.redeemCodeInfo.enableGift) {
            this.isShowEx = true;
          }
          this.$showCjToast({
            text: res.msg,
            type: "warn",
          }).then(() => {
            $this.$routerGo($this, "push", {
              path: "/member/myExchange/toExchange",
              query: { eExchangeCode: $this.eExchangeCode, cType: $this.redeemCodeInfo.type }
            });
          });
        } else {
          isLoading = false;
          if (res.eRcdId) {
            this.redeemCodeInfo.eRcdId = res.eRcdId;
            this.eExchangeCode = res.eRcdId;
            this.oldStartAt = res.startAt;
            this.oldEndAt = res.endAt;
            this.hasOldCode = true;
            if (this.redeemCodeInfo.type == 1 && this.redeemCodeInfo.prodInfo && this.redeemCodeInfo.prodInfo.permission) {
              this.resultStatus = 6;
            }
          }
          if ([6, 7, 9, 10, 11, 14].includes(this.resultStatus)) {
            this.isShowEx = false; // 领取失败不展示转赠好友
          }
          this.$showCjToast({
            text: res.detail || "领取失败",
            type: "warn",
          });
        }
      }, failRes => {
        this.isShowEx = false; // 领取失败不展示转赠好友
        this.hasGet = true;
        isLoading = false;
        this.$loading.hide();
      })
    },
    // 领取转赠的优惠券
    getReceiveCoupon() {
      if (localStorage.getItem("enableBindPhoneInRedeemCode") == 1 && !localStorage.getItem("uMobile")) {
        utilJs.goBindMobile()
      } else {
        if (isLoading) {
          return;
        }
        const $this = this
        isLoading = true;
        let url = `coupon/receiveCoupon`
        let data = {eRcdId: this.eRcdId}
        utilJs.postMethod(`${global.apiurl}${url}`, data, res => {
          isLoading = false;
          this.redeemCodeInfo.eRcdId = res.eRcdId;
          this.eExchangeCode = res.eRcdId;
          this.hasGet = true;
          if (this.redeemCodeInfo.type == 1) { // 兑换券的业务逻辑
            this.resultStatus = res.status;
            if (this.resultStatus == 8 && this.redeemCodeInfo.enableGift) {
              this.isShowEx = true;
            }
            if (this.resultStatus == 15 || (this.redeemCodeInfo.prodInfo && this.redeemCodeInfo.prodInfo.permission)) {
              this.resultStatus = 6;
              this.isShowEx = false;
              if (this.redeemCodeInfo.prodInfo && this.redeemCodeInfo.prodInfo.prodType == global.ckFrom.shopping) {
                this.getShopInfo(this.redeemCodeInfo.prodInfo.id, this.redeemCodeInfo.eRcdId);
                return;
              }
            }
          } else {
            this.resultStatus = 8;
          }
          this.$showCjToast({
            text: this.redeemCodeInfo.type == 1 && this.resultStatus == 6 ? "兑换成功" : "领取成功",
            type: "success",
          }).then(() => {
            // -1 未使用, 0 被占用，1 已使用, 2 线下核销
            const useStatus = [0, 1, 2].includes($this.redeemCodeInfo.useStatus)
            // 已领取的优惠券未使用 && 有eRcdId && 兑换券类型 && 已领取兑换券 && 不能转赠（能转赠还需要再点一次立即兑换，不会自动跳）&& 活动类型
            if (!useStatus && $this.redeemCodeInfo.type == 1 && $this.redeemCodeInfo.eRcdId && $this.redeemCodeInfo.type == 1 && $this.resultStatus == 8 && !$this.redeemCodeInfo.enableGift && $this.redeemCodeInfo.prodInfo && $this.redeemCodeInfo.prodInfo.prodType == global.ckFrom.activity) {
              // 活动票券兑换流程
              $this.getActivityInfo($this.redeemCodeInfo.prodInfo.id, $this.redeemCodeInfo.eRcdId, $this.redeemCodeInfo.prodInfo.subId)
            }
          });
        }, failRes => {
          this.isShowEx = false; // 领取失败不展示转赠好友
          this.hasGet = true;
          this.eExchangeCode = this.eRcdId;
          this.redeemCodeInfo.eRcdId = this.eRcdId;
          // 判断是不是本人已领取 8自己已领取；10已被别人领取
          this.resultStatus = this.redeemCodeInfo.recipientUserId == localStorage.getItem("userId") ? (this.redeemCodeInfo.type == 1 ? (this.redeemCodeInfo.useStatus == 1 ? 6 : (this.redeemCodeInfo.useStatus == -1 ? 8 : 10)) : 8) : 10;
          isLoading = false;
        })
      }
    },
    // 获取券包中的优惠券
    getCouponPack: function () {
      if (localStorage.getItem("enableBindPhoneInRedeemCode") == 1 && !localStorage.getItem("uMobile")) {
        utilJs.goBindMobile();
      } else {
        if (isLoading) {
          return;
        }
        isLoading = true;
        let $this = this;
        //sourse = 7 优惠券从分享页面领取
        let postData = {
          source: 7
        }
        if (this.$route.query.sourceForm) {
          postData.sourceForm = this.$route.query.sourceForm
        }
        if (this.$route.query.agentId) {
          postData.agentId = this.$route.query.agentId;
        }
        let url = `redeemCodes/collectRedeemCodeId/${this.redeemCodeInfo.encRedeemCodeId}`
        utilJs.postMethod(`${global.apiurl}${url}`, postData, res => {
          isLoading = false;
          this.resultStatus = res.status;
          if (this.redeemCodeInfo.validStatus == 1 || this.redeemCodeInfo.validStatus == 2) {
            this.redeemCodeInfo.startAt = res.startAt;
            this.redeemCodeInfo.endAt = res.endAt;
          }
          this.hasGet = true;
          this.isReceive = res.isReceive == 1 && (this.resultStatus == 8 || this.resultStatus == 15) ? 1 : 0;
          this.$loading.hide();
          if (this.resultStatus == 8) {
            if (this.redeemCodeInfo.enableGift) {
              this.isShowEx = true;
            }
            if (this.redeemCodeInfo.type == 1 && this.redeemCodeInfo.prodInfo && this.redeemCodeInfo.prodInfo.permission) {
              this.resultStatus = 6;
              // this.isShowEx = false;
            }
            this.redeemCodeInfo.eRcdId = res.eRcdId;
            this.eExchangeCode = res.eRcdId;
            this.$showCjToast({
              text: "领取成功",
              type: "success",
            }).then(() => {
              // -1 未使用, 0 被占用，1 已使用, 2 线下核销
              const useStatus = [0, 1, 2].includes($this.redeemCodeInfo.useStatus)
              // 已领取的优惠券未使用 && 有eRcdId && 不能转赠（能转赠还需要再点一次立即兑换，不会自动跳）&& 活动类型
              if (!useStatus && $this.redeemCodeInfo.type == 1 && $this.redeemCodeInfo.eRcdId && !$this.redeemCodeInfo.enableGift && $this.redeemCodeInfo.prodInfo && $this.redeemCodeInfo.prodInfo.prodType == global.ckFrom.activity) {
                // 活动票券兑换流程
                $this.getActivityInfo($this.redeemCodeInfo.prodInfo.id, $this.redeemCodeInfo.eRcdId, $this.redeemCodeInfo.prodInfo.subId)
              }
            });
          } else if (this.resultStatus == 15) {
            //15:兑换券只能兑换一种商品，则领取后直接兑换成功
            this.redeemCodeInfo.eRcdId = res.eRcdId;
            this.eExchangeCode = res.eRcdId;
            if (this.redeemCodeInfo.prodInfo && this.redeemCodeInfo.prodInfo.prodType == global.ckFrom.shopping) {
              this.getShopInfo(this.redeemCodeInfo.prodInfo.id, this.redeemCodeInfo.eRcdId);
            } else {
              this.$showCjToast({
                text: "兑换成功",
                type: "success",
              });
            }
          } else if (this.resultStatus == 17 || this.resultStatus == 18 || this.resultStatus == 19) {
            //15:兑换券只能兑换一种商品，则领取后直接兑换成功
            this.redeemCodeInfo.eRcdId = res.eRcdId;
            this.eExchangeCode = res.eRcdId;
            if (this.redeemCodeInfo.enableGift) {
              this.isShowEx = true;
            }
            this.$showCjToast({
              text: res.msg,
              type: "warn",
            });
          } else {
            isLoading = false;
            if (res.eRcdId) {
              this.redeemCodeInfo.eRcdId = res.eRcdId;
              this.redeemCodeInfo.useStatus = res.useStatus; // 已领取的优惠券是否已使用 -1 未使用, 0 被占用，1 已使用, 2 线下核销
              this.eExchangeCode = res.eRcdId;
              this.oldStartAt = res.startAt;
              this.oldEndAt = res.endAt;
              this.hasOldCode = true;
              if (this.redeemCodeInfo.type == 1 && this.redeemCodeInfo.prodInfo && this.redeemCodeInfo.prodInfo.permission) {
                this.resultStatus = 6;
              }
            }
            if ([6, 7, 9, 10, 11, 14].includes(this.resultStatus)) {
              this.isShowEx = false; // 领取失败不展示转赠好友
            }
            this.$showCjToast({
              text: res.detail || "领取失败",
              type: "warn"
            });
            // }
          }
        }, failRes => {
          this.isShowEx = false; // 领取失败不展示转赠好友
          isLoading = false;
          this.$loading.hide();
          // this.hasCommit = false;
        })
      }
    },
    getShopInfo(prodId, rcdId) {
      utilJs.getMethod(
        global.apiurl + "goods/goodsDetail?mgId=" + prodId + "&rcdId=" + rcdId,
        res => {
          if (res && res.redeemCodeData && res.redeemCodeData.status == 1) {
              this.shopInfo = res.goods;
              this.freeShipping = res.freeShipping;
              this.payAwardData = res.payAwardData;
              let shopInfo = [
                {
                  mgId: this.shopInfo.mgId,
                  mcId: "",
                  avatar: this.shopInfo.avatar ? this.shopInfo.avatar : "",
                  pointsDeduct: 0,
                  name: this.shopInfo.name,
                  price: 0,
                  originalPrice: this.shopInfo.originalPrice,
                  quantity: 1,
                  shopSpecInfo: "",
                  gsiiId: "",
                  postage: this.shopInfo.postage,
                  isMail: this.shopInfo.isMail,
                  isMallExpressDeliver: this.shopInfo.isMallExpressDeliver,
                  isMallOfflineDeliver: this.shopInfo.isMallOfflineDeliver,
                  stock: 1,
                  salesStock: "",
                  collageStock: "",
                  freeShipping: this.freeShipping,
                  isFlashSales: false,
                  isCollage: false,
                  pId: "",
                  noLimit: false,
                  vipDiscount: 0,
                  svipDiscount: 0,
                  agentDiscount: 0,
                  partnerDiscount: 0,
                  branchDiscount: 0,
                  isExchange: true,
                  limitType: -1,
                  limitNumber: 0,
                  purchasedNum: 0,
                  vipDiscountType: this.shopInfo.vipDiscountType || 1,
                  realPrice: this.shopInfo.price
                }
              ];
              sessionStorage.setItem("shopBuyInfo", JSON.stringify(shopInfo));
              let goPath = "/mall/shopSettlement/shopSettlement?shopNo=" + prodId + "&rcdId=" + rcdId;
              this.$routerGo(this, "push", {
                path: goPath
              });
          } else {
            this.$showCjToast({
              text: "兑换失败",
              type: "warn",
            });
          }
        }
      );
    },
    // 获取优惠券包信息
    getCouponInfo: function () {
      let postUrl = '';
      if (this.type == 1) {
        let moreUrl = this.rUserId != -1 ? `?sender=${this.rUserId}` : '';
        moreUrl += !!this.eRcdId ? `${this.rUserId != -1 ? '&' : '?'}eRcdId=${this.eRcdId}` : '';
        if (this.$route.query.agentId) {
          moreUrl += `${moreUrl != '' ? '&' : '?'}agentId=` + this.$route.query.agentId;
        }
        postUrl = `${global.apiurl}redeemCodes/getRedeemCodeInfo/${this.exchangeCode}` + moreUrl;
      } else {
        postUrl = `${global.apiurl}redeemCodes/getRedeemCodeDetailInfo/${this.exchangeCode}`;
        if (this.$route.query.agentId) {
          postUrl += '?agentId=' + this.$route.query.agentId;
        }
      }
      utilJs.getMethod(postUrl, res => {
        if (this.type == 2) {
          this.enableRelatedForm = res.data.enableRelatedForm;
        }
        this.codeStatus = res.data.status;
        this.redeemCodeId = res.data.redeemCodeId;
        this.redeemCodeInfo = res.data;
        setDocumentTitle(`领取${this.redeemCodeInfo.type == 1 ? '兑换' : '优惠'}券`);// eslint-disable-line
        if ((this.redeemCodeInfo.prodInfo && JSON.stringify(this.redeemCodeInfo.prodInfo) === '[]') || ((this.redeemCodeInfo.type == 2 || this.redeemCodeInfo.type == 3 || this.redeemCodeInfo.type == 5) && this.redeemCodeInfo.redeemType != 24)) {
          this.hasNoRecommendation = true;
        }
        if (this.redeemCodeInfo.validStatus != 1 && this.redeemCodeInfo.validStatus != 2 && this.redeemCodeInfo.startAt && this.redeemCodeInfo.endAt) {
          this.redeemCodeInfo.startAt = res.data.startAt.replace(/-/g, ".");
          this.redeemCodeInfo.endAt = res.data.endAt.replace(/-/g, ".");
        }
        this.wechatShare();
        this.getCouponProds();
      })
    },
    goHome: function () {
      if (this.redeemCodeInfo.redeemType == 25) {
        this.$routerGo(this, "push", {path: "/mall/classification/classificationAll"});
      } else {
        this.$routerGo(this, "push", {path: "/"});
      }
    },
    goToExchange: function () {
      if (this.hasNoRecommendation) {
        let toPath = this.redeemCodeInfo.redeemType == 25 ? '/mall/classification/classificationAll' : this.redeemCodeInfo.type == 4 ? '/homePage/booking/bookingList' : "/";
        this.$routerGo(this, "push", {
          path: toPath
        });
        return
      }

      // -1 未使用, 0 被占用，1 已使用, 2 线下核销
      const useStatus = [0, 1, 2].includes(this.redeemCodeInfo.useStatus)
      // 活动类型先走报名流程再兑换 已领取的优惠券未使用 && 有eRcdId && 活动类型
      if (!useStatus && this.redeemCodeInfo.type == 1 && this.redeemCodeInfo.eRcdId && this.redeemCodeInfo.prodInfo && this.redeemCodeInfo.prodInfo.prodType == global.ckFrom.activity) {
        // 活动票券兑换流程
        this.getActivityInfo(this.redeemCodeInfo.prodInfo.id, this.redeemCodeInfo.eRcdId, this.redeemCodeInfo.prodInfo.subId)
        return
      }
      if (this.eExchangeCode && this.eExchangeCode != 0 && this.redeemCodeInfo.type == 1 && this.redeemCodeInfo.prodInfo && this.redeemCodeInfo.enableGift) { // 如果是兑换券并且是兑换单个商品并且允许转赠的话，点击立即兑换，就进行兑换
        if (isLoading) {
          return;
        }
        isLoading = true;
        let postUrl = `${global.apiurl}redeemCodes/selectProdToRedeem/${this.eExchangeCode}`;
        utilJs.postMethod(postUrl, {prodId: this.redeemCodeInfo.prodInfo.id, prodType: this.redeemCodeInfo.prodInfo.prodType}, res => {
          this.resultStatus = 6;
          if (this.redeemCodeInfo.prodInfo && this.redeemCodeInfo.prodInfo.prodType == global.ckFrom.shopping) {
            this.getShopInfo(this.redeemCodeInfo.prodInfo.id, this.redeemCodeInfo.eRcdId);
          } else {
            this.isShowEx = false;
            this.$showCjToast({
              text: "兑换成功",
              type: "success"
            });
          }
          isLoading = false;
        }, failRes => {
          if (failRes.msg == "已有权限，无需再兑换！") {
            this.resultStatus = 6;
            this.isShowEx = false;
          }
          isLoading = false;
        })
      } else {
        this.$routerGo(this, "push", {
          path: "/member/myExchange/toExchange",
          query: { eExchangeCode: this.eExchangeCode, cType: this.redeemCodeInfo.type }
        });
      }
    },
    // 券包领取优惠券

    //分享
    wechatShare: function () {
      let title = '';
      if (this.type == 2) {
        title = this.redeemCodeInfo.shareConfig && this.redeemCodeInfo.shareConfig.shareTitle ? this.redeemCodeInfo.shareConfig.shareTitle : '快来领取兑换码';
      } else {
        title = this.redeemCodeInfo == null ? "快来领取兑换码" : this.redeemCodeInfo.shareTitle;
      }
      let shareImg = '';
      if (this.type == 2) {
        shareImg = this.redeemCodeInfo.shareConfig && this.redeemCodeInfo.shareConfig.sharePic ? this.redeemCodeInfo.shareConfig.sharePic : ('https://kposshzcdn.ckjr001.com/admin/material/9_material_admin/image/public/i/wap/coupon/share.png' || window.localStorage.getItem("shareLogo"));
      } else {
        shareImg = this.redeemCodeInfo && this.redeemCodeInfo.sharePic ? this.redeemCodeInfo.sharePic : ('https://kposshzcdn.ckjr001.com/admin/material/9_material_admin/image/public/i/wap/coupon/share.png' || window.localStorage.getItem("shareLogo"));
      }
      let shareUrl = "";
      // 有绑定服务商，推荐人id为服务商id，否则为当前用户id
      if (!this.redeemCodeInfo.presenterUserId || this.redeemCodeInfo.presenterUserId == -1) {
        shareUrl = `${window.location.href.split("#")[0]}#/homePage/giftcode/${this.exchangeCode}?type=${this.type}&refereeId=${localStorage.getItem("userId")}`;
      } else {
        shareUrl = `${window.location.href.split("#")[0]}#/homePage/giftcode/${this.exchangeCode}?type=${this.type}&refereeId=${this.redeemCodeInfo.presenterUserId}`;
      }
      if (this.$route.query.agentId) {
        shareUrl += '&agentId=' + this.$route.query.agentId;
      }
      let shareDesc = '';
      if (this.type == 2) {
        shareDesc = this.redeemCodeInfo.shareConfig && this.redeemCodeInfo.shareConfig.shareDesc ? this.redeemCodeInfo.shareConfig.shareDesc : (this.redeemCodeInfo.type == 1 ? "您有个兑换券可以领取，名额有限，快来领取吧！" : "您有个优惠券可以领取，名额有限，快来领取吧！");
      } else {
        shareDesc = this.redeemCodeInfo && this.redeemCodeInfo.shareDesc ? this.redeemCodeInfo.shareDesc : (this.redeemCodeInfo.type == 1 ? "您有个兑换券可以领取，名额有限，快来领取吧！" : "您有个优惠券可以领取，名额有限，快来领取吧！");
      }
      if (!this.redeemCodeInfo.enableShare || this.redeemCodeInfo.enableShare == -1) {
        if (this.$isWxApp()) { // 微信小程序分享路径重置到首页
          shareUrl = `${window.location.href.split("#")[0]}#/`;
          title = window.localStorage.getItem("shareTitle");
          shareImg = window.localStorage.getItem("shareLogo");
          shareDesc = window.localStorage.getItem("shareDesc");
          console.log(shareUrl, title, shareImg, shareDesc);
        }
        utilJs.wechatConfig(shareUrl, title, shareImg, shareDesc, function () { }, false, { hideAllNonBaseMenuItem: 1 });
      } else {
        utilJs.wechatConfig(shareUrl, title, shareImg, shareDesc, function () { }, true, { hideAllNonBaseMenuItem: 0 });
      }
    },
    //手机端分享
    appShare: function () {
      let title = '';
      if (this.type == 2) {
        title = this.redeemCodeInfo.shareConfig && this.redeemCodeInfo.shareConfig.shareTitle ? this.redeemCodeInfo.shareConfig.shareTitle : '快来领取兑换码';
      } else {
        title = this.redeemCodeInfo == null ? "快来领取兑换码" : this.redeemCodeInfo.shareTitle;
      }
      let shareImg = '';
      if (this.type == 2) {
        shareImg = this.redeemCodeInfo.shareConfig && this.redeemCodeInfo.shareConfig.sharePic ? this.redeemCodeInfo.shareConfig.sharePic : ('https://kposshzcdn.ckjr001.com/admin/material/9_material_admin/image/public/i/wap/coupon/share.png' || window.localStorage.getItem("shareLogo"));
      } else {
        shareImg = this.redeemCodeInfo && this.redeemCodeInfo.sharePic ? this.redeemCodeInfo.sharePic : ('https://kposshzcdn.ckjr001.com/admin/material/9_material_admin/image/public/i/wap/coupon/share.png' || window.localStorage.getItem("shareLogo"));
      }
      let shareUrl = "";
      // 有绑定服务商，推荐人id为服务商id，否则为当前用户id
      if (!this.redeemCodeInfo.presenterUserId || this.redeemCodeInfo.presenterUserId == -1) {
        shareUrl = `${window.location.href.split("#")[0]}#/homePage/giftcode/${this.exchangeCode}?type=${this.type}&refereeId=${localStorage.getItem("userId")}`;
      } else {
        shareUrl = `${window.location.href.split("#")[0]}#/homePage/giftcode/${this.exchangeCode}?type=${this.type}&refereeId=${this.redeemCodeInfo.presenterUserId}`;
      }
      if (this.$route.query.agentId) {
        shareUrl += '&agentId=' + this.$route.query.agentId;
      }
      let shareDesc = '';
      if (this.type == 2) {
        shareDesc = this.redeemCodeInfo.shareConfig && this.redeemCodeInfo.shareConfig.shareDesc ? this.redeemCodeInfo.shareConfig.shareDesc : (this.redeemCodeInfo.type == 1 ? "您有个兑换券可以领取，名额有限，快来领取吧！" : "您有个优惠券可以领取，名额有限，快来领取吧！");
      } else {
        shareDesc = this.redeemCodeInfo && this.redeemCodeInfo.shareDesc ? this.redeemCodeInfo.shareDesc : (this.redeemCodeInfo.type == 1 ? "您有个兑换券可以领取，名额有限，快来领取吧！" : "您有个优惠券可以领取，名额有限，快来领取吧！");
      }
      if (!this.redeemCodeInfo.enableShare || this.redeemCodeInfo.enableShare == -1) {
        utilJs.appShareTrue(title, shareImg, shareUrl, shareDesc, function () { }, false, { hideAllNonBaseMenuItem: 1 });
      } else {
        utilJs.appShareTrue(title, shareImg, shareUrl, shareDesc, function () { }, true, { hideAllNonBaseMenuItem: 0 });
      }
    },
  },
  activated() {
    this.isOpenSharePopup = false;
    this.hasGet = false;
    this.rUserId = "";
    this.codeStatus = -999;
    this.resultStatus = -999;
    this.redeemCodeInfo = "";
    this.startAt = "";
    this.endAt = "";
    this.rUserId = this.$route.query.refereeId ? this.$route.query.refereeId : -1;
    this.exchangeCode = this.$route.params.exchangeCode;
    this.type = this.$route.query.type || 2; //1为券包 2为单张优惠券
    this.isGoUse = Number(this.$route.query.isGoUse) == 1 ? true : false;
    this.showMask = false;
    this.showUse = false;
    this.hasOldCode = false;
    this.buttonText = "立即使用";
    this.hasNoRecommendation = false;
    this.exchangeArr = [];
    pageIndex = 1;
    this.dataStatus = 'HAS_MORE_DATA';
    this.isShowEx = false;
    this.eExchangeCode = 0;
    this.eRcdId = this.$route.query.eRcdId || '';
    this.isGift = this.$route.query.isGift || 0;
    this.shareQrCode = '';
    this.isReceive = 0;
    if (this.type == 1) {
      this.dataStatus = 'NO_DATA';
    }
    this.getCouponInfo();
    getBindPhoneSetting(global.ckFrom.coupon).then(res => {
      this.bindPhoneSetting = res;
    });
    window.addEventListener('scroll', this.windowScrollFunction);
  },
  deactivated() {
    window.removeEventListener('scroll', this.windowScrollFunction);
  }
}
</script>
<style scoped>
em {
  font-style: normal;
}
.wechat{
  color: #76DA7D;
}
.last-bg {
  background: url("../../../../public/i/wap/coupon/last-bg.png") no-repeat
    100%;
  background-size: 100% 104%;
}
.c-pv17 {
  padding-top: 0.425rem;
  padding-bottom: 0.425rem;
}
.c-coupon-bg {
  background: url("https://kposshzcdn.ckjr001.com/2087/resource/admin-fe_jzr8_SHs3zxfcRKJy5rbxDfFC.png") no-repeat
    100%;
  background-size: 100% 104%;
}
.c-exchange-bg {
  background: url("https://kposshzcdn.ckjr001.com/2087/resource/admin-fe_jzr8_ndmtMJrhyz3js2k75jbF.png") no-repeat
    100%;
  background-size: 100% 104%;
}
.exchange-left-bg {
  width: 120px;
  height: 84px;
  background: url("https://knowledge-payment.oss-cn-beijing.aliyuncs.com/lj7l/resource/imgs/511312fa/admin-fe_lj7l_uploadBox_QMbN3zxeNFeSXhJ6NtKA.png") no-repeat
    100%;
  background-size: 100% 100%;
}
.c-exchange-st {
  border-top: 1px solid #FEB347;
  border-right: 1px solid #FEB347;
  border-bottom: 1px solid #FEB347;
  background: rgba(254,179,71,0.05);
}
.used{
  background: linear-gradient(90deg,#fc787c, #f98271 99%);
}
.margin-auto {
  margin: auto;
}
.share-wrap {
  padding-top: 120px;
  padding-left: 120px;
}
.mt130 {
  margin-top: 130px;
}
.canvasBox {
  top: -999px;
  left: -1000px;
  z-index: -999;
  position: absolute;
  /* background: rgba(155, 0, 0, 0); */
  /* background-color: #fff; */
}
.w600px {
  width: 600px;
}
.w440px {
  width: 440px;
}
.pl40px {
  padding-left: 40px;
}
.c-ww72px {
  width: 72px;
}
.c-hh72px {
  height: 72px;
}
.c-ml16px {
  margin-left: 16px;
}
.c-fs24px {
  font-size: 24px;
}
.c-fs18px {
  font-size: 18px;
}
.c-ww380px {
  width: 380px;
}
.c-ww394px {
  width: 394px;
}
.c-mt56px {
  margin-top: 56px;
}
.c-fs20px {
  font-size: 20px;
}
.c-ww140px {
  width: 140px;
}
.c-hh140px {
  height: 140px;
}
.c-hh139px {
  height: 142px;
}
.c-fs32px {
  font-size: 32px;
}
.c-pb10px {
  padding-bottom: 10px;
}
.c-fs40px {
  font-size: 40px;
}
.c-ph12px {
  padding-left: 12px;
  padding-right: 12px;
}
.c-ph24px {
  padding-left: 24px;
  padding-right: 24px;
}
.c-pv17px {
  padding-top: 17px;
  padding-bottom: 17px;
}
.c-fs28px {
  font-size: 28px;
}
.c-mt100px {
  margin-top: 100px;
}
.c-ww130px {
  width: 130px;
}
.c-ww120px {
  width: 120px;
}
.c-ww140px {
  width: 140px;
}
.c-hh130px {
  height: 130px;
}
.c-fs22px {
  font-size: 22px;
}
.c-mt24px {
  margin-top: 24px;
}
.c-br8px {
  border-radius: 8px;
}
.c-page-bg {
  /* height: 100%; */
  /* background: url("https://kposshzcdn.ckjr001.com/admin/material/9_material_admin/image/public/i/wap/coupon/page_bg.png") no-repeat
    100%; */
  background-size: 100% 100%;
}
.exchange-content {
  width: 14.8rem;
  height: 22rem;
  margin: 1rem auto;
  /* background: url("https://kposshzcdn.ckjr001.com/admin/material/9_material_admin/image/public/i/wap/coupon/exchange_inner.png") no-repeat
    100%; */
  background-size: 100% 100%;
  box-shadow:0px 6px 14px 0px rgba(85, 5, 5, 0.1);
}
.bd1-syellow {
  border-bottom: 1px dashed #cab1a1;
}
.b1-syellow {
  border-bottom: 1px solid #cab1a1;
}
.c-mh132 {
  margin-left: 3.3rem;
  margin-right: 3.3rem;
}
.to-use {
  background: linear-gradient(180deg,#ffea44, #ffae00);
}
.has-get {
  background: #F9F7F7;
}
.fc-get {
  color: #E63919;
}
.btn {
  background-image: linear-gradient(0deg, #FFC034 0%, #FFEEBA 100%);
  color: #FE4D2D;
}
.c-tag-br12 {
  border-radius: 0.3rem 0 0.3rem 0;
}
.has-get-bg {
  background-image: linear-gradient(0deg, #FFDB8D 0%, #FFFFFF 100%);
  color: #FE4D2D;
}
.c-mt140 {
  margin-top: 3.5rem;
}
.c-mt110 {
  margin-top: 2.75rem;
}
</style>

